<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  request.setAttribute("now",new Date());
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">资产报废登记表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_assetscrap_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${assetScrap.id}" />

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_asset_dialog_select('name','assetId')" style="color: #0a6dbd">资产名称</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="name" name="name" class="form-control" value="${assetScrap.name}" disabled>
                        <input type="hidden" name="assetId" id="assetId" value="${assetScrap.asset.id}" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资产编号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="assetNo" name="assetNo" class="form-control" value="${assetScrap.asset.assetNo}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">规则型号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="model" name="model" class="form-control" value="${assetScrap.asset.model}" disabled>
                    </div>
                </div>

                <div class="form-group div-Hidden">
                    <label class="col-md-2 control-label">采购日期<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <div class="input-group date">
                            <input type="text" class="form-control" id="datPurchase" name="datPurchase" disabled
                                   value=<fmt:formatDate pattern="yyyy-MM-dd" value="${assetScrap.asset.datPurchase}" /> >
                            <span class="input-group-addon"><i class="ti-calendar"></i></span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">采购金额<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="number" id="purchaseMoney" name="purchaseMoney" class="form-control" value="${assetScrap.asset.purchaseMoney}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">报废原因<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <select id="dictItemId" name="dictItemId" class="form-control">
                            <option></option>
                            <c:forEach var="item" items="${dictItems}" varStatus="status">
                                <option value="${item.id}" <c:if test="${item.id == infile.dictItem.id}"> selected="selected"</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        已提折旧（元）
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="number" id="numYTZJMoney" name="numYTZJMoney" class="form-control" placeholder="请输入已提折旧" value="${assetScrap.numYTZJMoney}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        净值（元）
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="number" id="numNetMoney" name="numNetMoney" class="form-control" placeholder="请输入净值" value="${assetScrap.numNetMoney}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        残值（元）
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="number" id="numLeftMoney" name="numLeftMoney" class="form-control" placeholder="请输入残值" value="${assetScrap.numLeftMoney}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">相关附件</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="fileAttachment" placeholder="" type="file" >
                        <input name="hiddenFiles" id="hiddenFilesAttachment" type="hidden" value="${assetScrap.fileAttachment}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${assetScrap.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${assetScrap.dateApply}" /></p>
                    </div>
                </div>

            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

            <div class="panel-footer">
                <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                    <i class="fa fa-lg fa-mail-reply"></i> 返回视图
                </a>
                <c:if test="${assetScrap.numStatus==0}">
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存表单 </a>
                    <a class="btn btn-warning" id="btn-submit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交表单 </a>
                </c:if>
            </div>

        </div>
    </div>
</div>

<script>
    // 字典列表下拉框
    $("#dictItemId").select2({
        placeholder: "请选择一个报废原因",
        allowClear: true
    });

    // 附件上传
    inputLoad({
        objId:"fileAttachment",
        entityName:"fileAttachment",
        sourceId:"hiddenFilesAttachment"
    });

    // 资产选择框
    function fn_asset_dialog_select(nameField,idField) {
        __open_dialog_select('选择资产', '<%=path%>/activiti/asset/dialogs?category=3', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#'+idField).val(data.id);
                    $('#'+nameField).val(data.name);

                    $('#assetNo').val(data.assetNo);
                    $('#datPurchase').val(data.datPurchase);
                    $('#purchaseMoney').val(data.purchaseMoney);
                    $('#model').val(data.model);
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_asset_select(callback);
        });
    }

    //校验
    function infoValidate() {
        var tmp = "";

        tmp = $("input#assetId").val();
        if(!tmp){
            __toastr_error("请选择资产！");
            return false;
        }

        tmp = $("select#dictItemId").val();
        if(!tmp){
            __toastr_error("请选择报废原因！");
            return false;
        }

        tmp = $("input#numYTZJMoney").val();
        if(!tmp){
            __toastr_error("请输入已提折旧！");
            return false;
        }

        tmp = $("input#numNetMoney").val();
        if(!tmp){
            __toastr_error("请输入净值！");
            return false;
        }

        tmp = $("input#numLeftMoney").val();
        if(!tmp){
            __toastr_error("请输入残值！");
            return false;
        }

        return true;
    }

    //保存
    $("#btn-save-common").click(
        function(e) {
            __confirm_dialog("提示：","确定保存吗？",
                function () {
                    __form_save("form_assetscrap_input", "<%=path%>/activiti/assetscrap/save");
                    returnToHashUrl();
                }
            )
        }
    );

    //提交
    $("#btn-submit-common").click(
        function(e) {
            var $valid = infoValidate();
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                function () {
                    __form_save("form_assetscrap_input", "<%=path%>/activiti/assetscrap/submit");
                    returnToHashUrl();
                }
            )
        }
    );
    //返回视图
    $("#apply-re-common").click(returnToHashUrl);

    // 加载完成后执行
    $(function(){
       

    })

</script>
